import { articleApi } from '@/plugins/api'

const state = () => ({
    viewsList: [],
    idList: []
})

const mutations = {
    getArticleOrderList(state, data) {
        if (data[1] === 'views') {
            state.viewsList = data[0].rows
        } else if (data[1] === 'id') {
            state.idList = data[0].rows
        }
    }
}

const actions = {
    async getArticleOrderList({ commit }, obj) {
        // 获取文章
        let params = {
            sort: obj.sort,
            pageSize: obj.pageSize
        }
        const { err, data } = await articleApi.getTypeSort(params)
        if (err) {
            return false
        }
        commit('getArticleOrderList', [data, obj.sort])
    }
}

export default { namespaced: true, state, mutations, actions }
